/*
* @Author: steven.wang
* @Date:   2019-05-08 16:18:51
* @Last Modified by:   steven.wang
* @Last Modified time: 2019-05-15 17:12:32
*/
const db = require('../db');
/**
 * 获取网址分类
 * @author steven.wang
 * @DateTime 2019-05-15T15:50:33+0800
 */
module.exports.listCategory = values => {
	const dbSql = db.generateSql({
		wants: '*',
		action: 'search',
		table: 'navi_category',
		conditions: values.conditions
	});
	return db.query(dbSql.sql, dbSql.sqlData);
}
/**
 * 添加网址分类
 * @author steven.wang
 * @DateTime 2019-05-15T15:50:33+0800
 */
module.exports.addCategory = values => {
	const dbSql = db.generateSql({
		action: 'add',
		table: 'navi_category',
		conditions: values.conditions
	});
	return db.query(dbSql.sql, dbSql.sqlData);
}

/**
 * 获取网址
 * @author steven.wang
 * @DateTime 2019-03-23T03:38:45+0800
 */
module.exports.list = values => {
	const dbSql = db.generateSql({
		wants: '*',
		action: 'search',
		table: 'navi',
		conditions: values.conditions,
		likes: values.likes,
		sorts: values.sorts,
		pages: values.pages
	});
	return db.query(dbSql.sql, dbSql.sqlData);
}
/**
 * 获取网址导航总数
 * @author steven.wang
 * @DateTime 2019-03-23T03:38:45+0800
 */
module.exports.count = values => {
	const dbSql = db.generateSql({
		wants: 'count(*)',
		action: 'search',
		table: 'navi',
		conditions: values.conditions,
		likes: values.likes,
	})
	return db.query(dbSql.sql, dbSql.sqlData);
}
/**
 * 添加网址导航
 * @author steven.wang
 * @DateTime 2019-03-23T03:38:45+0800
 */
module.exports.add = values => {
	const dbSql = db.generateSql({
		action: 'add',
		table: 'navi',
		conditions: values.conditions
	});
	return db.query(dbSql.sql, dbSql.sqlData);
}

/**
 * 删除网址导航
 * @author steven.wang
 */
module.exports.delete = values => {
	const dbSql = db.generateSql({
		action: 'delete',
		table: 'navi',
		conditions: {
			id: values.ids
		}
	});
	return db.query(dbSql.sql, dbSql.sqlData);
}

/**
 * 更新网址导航
 * @author steven.wang
 * @DateTime 2019-03-23T03:38:45+0800
 */
module.exports.update = values => {
	let id = values.id;
	delete values.id;
	const dbSql = db.generateSql({
		action: 'update',
		table: 'navi',
		wants: values,
		conditions: {
			id: id
		}
	});
	return db.query(dbSql.sql, dbSql.sqlData);
}